"""
selenium抓取猫眼电影top100
"""

from selenium import webdriver

# 1.打开浏览器,进入主页
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)

driver.get(url='https://maoyan.com/board/4')

# 2.提取数据
def get_one_page():
    dd_list = driver.find_elements_by_xpath('//dl/dd')
    for dd in dd_list:
        # text属性:获取当前节点及子节点和后代节点文本
        li = dd.text.split('\n')
        item = {}
        item['rank'] = li[0]
        item['title'] = li[1]
        item['star'] = li[2]
        item['time'] = li[3]
        item['score'] = li[4]
        print(item)

while True:
    get_one_page()
    try:
        driver.find_element_by_link_text('下一页').click()
    except Exception as e:
        driver.quit()
        break






























